package com.powernode.web.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 统一的返回结果类型
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CommonResult {

    private Integer code;
    private String text;
    private Object data;

    // 利用构建器模式快速创建结果类型
    public static CommonResult ok() {
        return CommonResult.builder()
                .code(RespCode.OK.getCode())
                .text(RespCode.OK.getText())
                .build();
    }
    public static CommonResult ok(Object data) {
        return CommonResult.builder()
                .code(RespCode.OK.getCode())
                .text(RespCode.OK.getText())
                .data(data)
                .build();
    }
    public static CommonResult fail(RespCode respCode) {
        return CommonResult.builder()
                .code(respCode.getCode())
                .text(respCode.getText())
                .build();
    }
}
